package com.ce.pms.house.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.house.dao.IManageOrgDao;
import com.ce.pms.house.model.ManageOrgDomain;
import com.ce.pms.house.vo.ManageOrgVO;

public class ManageOrgDaoImpl extends PmsBaseDaoImpl<ManageOrgDomain> implements IManageOrgDao {
	/**
	 * 功能描述:根据管理处名字查询记录数<br>
	 * 注：新建判断name的唯一性时，oldName为null；修改判断name的唯一性时，则需要传入修改前的名字<br>
	 * @param manageOrgByName
	 * @param oldName
	 * @return
	 * Create author:胡煦
	 * Create on:2008-7-14
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public Long checkManageOrgByName(String manageOrgByName,String oldName){
		StringBuffer hql=new StringBuffer();
		List list = new ArrayList();
		list.add(manageOrgByName);

		hql.append("select count(*) FROM  ManageOrgDomain mo WHERE mo.name = ? ");
		if(oldName!=null){
			hql.append(" and mo.name <> ?");
			list.add(oldName);
		}
		Query query=this.createQuery(hql.toString(), list.toArray());
		Object result=query.uniqueResult();
		return (result == null ? null : (Long)result );

	}

}
